#!/bin/sh

set -e

echo "start to prepare build env"
chmod +x /root/repo/ci-repos/.common_scripts/common.sh
source /root/repo/ci-repos/.common_scripts/common.sh
set_gitee_hosts
prepare_git $1 $2
prepare_conan2 $3 $4

sh install_local.sh
prepare_sdk

echo "start to execute build"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BUILDER_SCRIPT="${SCRIPT_DIR}/build.py"

if [ ! -f "${BUILDER_SCRIPT}" ]; then
    echo "Error: Missing ${BUILDER_SCRIPT}"
    exit 1
fi

REPOS=(
    "bios=https://gitcode.com/openUBMC/bios.git"
)

PY_ARGS="--manifest-path ~/manifest"
IFS=' '
set -- ${REPOS[@]}

python3 ${BUILDER_SCRIPT} "$@" ${PY_ARGS} || {
    echo "FATAL: Build failed with exit code $?"
    exit 1
}